STEP 11: Time to count how much time has passed!

Variables created OUTSIDE an event can't be changed INSIDE an event. We use the keyword global to make an exception to this rule. global lets us use a variable inside and outside of an event.

  • In LOGIC, click on and drag out Global Variable INSIDE your interval event.
  • Change the variable after global from my_var to time.

To navigate the page using the TAB key, first press ESC to exit the code editor.

microbit = codesters.Microbit() microbit.show_string("hello") data = microbit.get_temp() microbit.show_number(data) data_list = [] time_list = [] my_display = codesters.ScatterPlot(time_list, data_list) time = 0 def interval(): data = microbit.get_temp() data_list.append(data) stage.event_interval(interval, 2)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)